/*
 *  Cero Project - Copyright   2006 The Cero Developement Team 
 *  (Michael Laguerre, Camille Roux, Matthieu Segret, Mathieu Sivade) 
 * 
 *  This program is free software; you can redistribute it and/or modify it 
 *  under the terms of the GNU General Public License as published by the Free 
 *  Software Foundation; either version 2 of the License, or (at your option) 
 *  any later version.
 * 
 *  This program is distributed in the hope that it will be useful, but 
 *  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 *  or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 
 *  for more details.
 */

package org.ceroproject.games.base;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.ceroproject.games.GameEvent;
import org.ceroproject.games.GameListener;
import org.ceroproject.games.Player;


public class ScoreManager implements GameListener {
	private Map<Player, List<Integer>> scores = new HashMap<Player, List<Integer>>();

	public void gameStart(GameEvent e) {
		for (Player p : e.getGame().getPlayers()) {
			List<Integer> l = new ArrayList<Integer>();
			l.add(0);
			scores.put(p, l);
		}
	}

	public void gameEnd(GameEvent e) {
	}

	public void addPoints(Player p, int points) {
		List<Integer> l = scores.get(p);
		if (l == null)
			throw new RuntimeException(
					"This version of score manager doesn't allow players to come in the middle of the game");
		l.add(l.get(l.size() - 1).intValue() + points);
	}

	public List<Integer> getScoreList(Player p) {
		return new ArrayList<Integer>(scores.get(p));
	}

	public int getCurrentScore(Player p) {
		return scores.get(p).get(scores.get(p).size() - 1);
	}

}
